<?php
	//
	class GalleryView {
		private $gal_submit = 'gal_submit';
		private $profile = '?profile';
		//
		const GAL_NO_MESSAGE = "";
		const GAL_WRONG_FILE_TYPE = 1;
		const GAL_PHOTO_EXISTS = 2;
		const GAL_SUBMIT_SUCCESS = 3;
		//
		public function DoUploadBox($active_user, $gal_message){	
			return "
				<nav class='usermenu'>
					<ul>
						<li><p>$active_user</p>'s <a href='$this->profile'>Profil</a> |</li>
						<li><a href='#'>Fotoalbum</a></li>    
					</ul>
				</nav>
				<form method='post' enctype='multipart/form-data' class='gallery'>
				<input type='file' name='file'/>
				<input type='submit' name='$this->gal_submit' value='Ladda upp' class='galbutton'/>
				$gal_message
				</form>
			";
		}
		//
		public function DoGallery(){
			$directory = opendir("Gallery/Photos/");			
			$gallery = "";
			while (($photo = readdir($directory)) == true){
				if (($photo != ".") && ($photo != "..")) {
					$gallery .= "<img src='Gallery/Photos/$photo' height='140' class='photos'>";
				}
			}
			closedir($directory);				
			return $gallery;	
		}
		//
		public function Files(){
			return $_FILES;
		}
		//
		public function TriedToSubmit(){
			if (isset($_POST[$this->gal_submit])){
				return true;
			}		
			return false;
		}
		//
		public function GetMessage($status){
			switch ($status){
				case self::GAL_WRONG_FILE_TYPE:
					$gal_message = "<p class='galmessage'>Du kan endast ladda upp bilder av typen .png, .jpg och .jpeg!</p>";
					break;
				case self::GAL_PHOTO_EXISTS:
					$gal_message = "<p class='galmessage'>Det finns redan en bild med samma namn i ditt fotoalbum!</p>";
					break;
				case self::GAL_SUBMIT_SUCCESS:
					$gal_message = "<p class='galmessage'>Din bild är sparad!</p>";
					break;
				default:			
					break;
			}
			return $gal_message;
		}
	}
?>